library(hydroGOF)

data1=read.csv("C:/data/all_daily_merge.csv")
data1=subset(data1,data1$station!=3)


model1=lm(data1$pm25~data1$aod+data1$temp+data1$avg_temp+data1$avg_rh+data1$avg_preci_24)

pm25model=model1$fitted.values
model1_re=sum(abs(data1$pm25-pm25model)/data1$pm25)/nrow(data1)*100
model1_rmse=rmse(data1$pm25,pm25model)
model1_r=cor(data1$pm25,pm25model)

print("Model 1:")
print(paste("Number of sample: ",nrow(data1)))
print(paste("R2:",round(model1_r*model1_r,3)))
print(paste("RMSE:",round(model1_rmse,3)))
print(paste("RE:",round(model1_re,3)))


data1=subset(data1,abs(data1$pm25-pm25model)<3*model1_rmse)
model1=lm(data1$pm25~data1$aod+data1$temp+data1$avg_temp+data1$avg_rh+data1$avg_preci_24)
pm25model=model1$fitted.values
model1_re=sum(abs(data1$pm25-pm25model)/data1$pm25)/nrow(data1)*100
model1_rmse=rmse(data1$pm25,pm25model)
model1_r=cor(data1$pm25,pm25model)


print("Model 1:")
print(paste("Number of sample: ",nrow(data1)))
print(paste("R2:",round(model1_r*model1_r,3)))
print(paste("RMSE:",round(model1_rmse,3)))
print(paste("RE:",round(model1_re,3)))


